package com.wf.netty.link;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.nio.charset.Charset;
import java.util.List;

/**
 * 解码器
 *
 * @author wf
 * @since 2022/5/12
 */
public class ServerDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int i = in.readableBytes();
        out.add(in.readBytes(i).toString(Charset.defaultCharset()));
        out.add("from client");
        System.out.println("out is " + out);
    }
}
